package com.yhsimon.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class ModelTest {

    //使用ServletAPI  详见教程文档
    @RequestMapping("/m/t1")
    public String test1(HttpServletRequest request, HttpServletResponse response){
        System.out.println(request.getSession().getId());
        return "test";
    }

    //通过SpringMVC来实现转发和重定向-无需视图解析器
    @RequestMapping("/mvc/t2")
    public String test2(Model model){
        //转发
        model.addAttribute("msg", "无需视图解析器-转发");
//        return "/index.jsp";
        return "/WEB-INF/jsp/test.jsp";
    }

    @RequestMapping("/mvc/t3")
    public String test3(Model model){
        model.addAttribute("msg", "无需视图解析器-转发-forward");
        //转发二
        return "forward:/WEB-INF/jsp/test.jsp";
    }

    @RequestMapping("/mvc/t4")
    public String test4(Model model){
        model.addAttribute("msg", "无需视图解析器-重定向-redirect");
        //重定向
        return "redirect:/index.jsp";
    }
}
